package mww.javabean.service;

import java.util.List;
import java.util.Map;

import mww.common.DaoException;
import mww.javabean.dao.TeacherDaoImpl;
import mww.javabean.dao.TeacherDao;

import mww.common.ServiceException;
import mww.javabean.entity.Teacher;

public class TeacherServiceImpl implements TeacherService {
	private TeacherDao teacherDao = new TeacherDaoImpl();
	//添加教师方法
	@Override
	public void addTeacher(Teacher teacher) throws ServiceException{
		try{
			teacherDao.addTeacher(teacher);
		}catch(DaoException e){
			e.printStackTrace();
			throw new DaoException(e.getMessage(),e);
		}
	}
	//删除教师方法
	@Override
	public void delTeacher(String teacherNo) throws ServiceException{
		try{
			teacherDao.delTeacher(teacherNo);
		}catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(),e);
		}
	}
	//修改教师信息
	@Override
	public void updateTeacher(Teacher teacher) throws ServiceException{
		try{
			teacherDao.updateTeacher(teacher);
		}catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(),e);
		}
	}
	//根据教师编号查找教师
	@Override
	public Teacher findTeacherByTeacherNo(String teacherNo) throws ServiceException {
		Teacher teacher=null;
		try{
			teacher = teacherDao.findTeacherByTeacherNo(teacherNo);
		}catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(),e);
		}
		return teacher;
	}
	//列表显示所有教师列表--分页
	@Override
	public Map findAllTeacher(Integer curPage) throws ServiceException {
		Map map=null;
		try{
			map = teacherDao.findAllTeacher(curPage);
		}catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(),e);
		}
		return map;
	}
	//多条件查询教师
	@Override
	public List findAllTeacherByMostCon(Teacher condition) throws ServiceException{
		List list = null;
		try{
			list = teacherDao.findAllTeacherByMostCon(condition);
		}catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(),e);
		}
		return list;
	}
	//多条件查询教师-带分页
	@Override
	public Map findAllTeacherByMostCon(Teacher condition, Integer curPage) throws ServiceException {
		Map map=null;
		try{
			map = teacherDao.findAllTeacherByMostCon(condition, curPage);
		}catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(),e);
		}
		return map;
	}
	@Override
	public int getTeacherTotality() throws ServiceException {
		Integer teacherTol = null;
		try{
			teacherTol = teacherDao.findAllTeacher().size();
		}catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(),e);
		}
		return teacherTol;
	}
	
	//列表显示所有教师列表
	@Override
	public List findAllTeacher()  throws ServiceException{
		List list = null;
		try{
			list = teacherDao.findAllTeacher();
		}catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(),e);
		}
		return list;
	}
	@Override
	public void updatePwd(String loginName, String newPassword) throws ServiceException {
		try{
			teacherDao.changePwd(loginName, newPassword);
		}catch(DaoException e){
			e.printStackTrace();
			throw new DaoException(e.getMessage(),e);
		}
	}
}
